using System;
using Common.Commands.NoteCommands;
using Common.Enumerations;
using Common.Views;
using Core.Domain.Model;
using NUnit.Framework;
using Sanelib.Common.Extensions;
using Sanelib.Common.Helpers;
using Sanelib.DataView;
using Sanelib.Dto.Enumerations;

namespace IntegrationTests.Processors
{
    public class NoteProcessorTester : IntegrationTestBase
    {
        [Test]
        public void ShouldAddNote()
        {
            var member = new Member
            {
                Id = GuidComb.New(),
                Code = "Admin",
                Name = "Admin",
                DateOfBirth = DateTime.Now.AddYears(-20),
                Address = "adminAddress",
                Email = "sunny@sanelib.com",
                Mobile = "9099791517",
                ScreenMessage = "Hi, Admin",
                ValidFrom = DateTime.Now.AddMonths(-1),
                ValidTo = DateTime.Now.AddMonths(2),
                SendSms = true,
                SendEmail = true,
                UsePrint = true,
                Block = false,
                Role = Role.ApplicationOwner,
                UserStatus = UserStatus.Active,
                ImageData = ImageUtility.NoImageData
            };

            Persist(member);

            var command = new AddNote
            {
                Id = GuidComb.New(),
                Name = "Details",
                EntityType = EntityType.Account,
                ReferenceId = GuidComb.New(),
                ReferenceName = "Account",
                Description = "Finance Account",
                ImageData = ImageUtility.NoImageData,
                UserId = member.Id
            };
            ProcessCommand(command);
            var repo = GetInstance<IViewRepository<NoteView>>();
            var noteView = repo.GetById(command.Id);

            Assert.AreEqual(command.Description, noteView.Description);
        }

        [Test]
        public void ShouldDeleteNote()
        {
            var note = new Note
            {
                Id = GuidComb.New(),
                Name = "Details",
                ImageData = ImageUtility.NoImageData,
                EntityType = EntityType.Account,
                ReferenceId = GuidComb.New(),
                ReferenceName = "Account",
                Description = "Finance Account"
            };
            Persist(note);

            var command = new DeleteNote(note.Id);
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<NoteView>>();
            var noteView = repo.GetById(command.Id);

            Assert.IsNull(noteView);
        }

        [Test]
        public void ShouldUpdateNote()
        {
            var note = new Note
            {
                Id = GuidComb.New(),
                Name = "Details",
                EntityType = EntityType.Account,
                ReferenceId = GuidComb.New(),
                ReferenceName = "Account",
                Description = "Finance Account",
                ImageData = ImageUtility.NoImageData
            };
            Persist(note);

            var command = new UpdateNote
            {
                Id = note.Id,
                Name = "Notes",
                EntityType = note.EntityType,
                ReferenceId = note.ReferenceId,
                ReferenceName = note.ReferenceName,
                Description = "Sales Account",
                ImageData = ImageUtility.NoImageData
            };
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<NoteView>>();
            var noteView = repo.GetById(command.Id);

            Assert.AreEqual(noteView.Id, note.Id);
            Assert.AreNotEqual(command.Description, note.Description);
        }
    }
}